import 'package:flutter/foundation.dart';
import 'package:permission_handler/permission_handler.dart';

class PermissionUtils {
  PermissionUtils._internal();

  /// 请求单个权限
  static Future<PermissionStatus> checkAndRequestPermission(
    Permission permission,
  ) async {
    if (await permission.isGranted) {
      return PermissionStatus.granted;
    }
    if (await permission.isPermanentlyDenied) {
      return PermissionStatus.permanentlyDenied;
    }

    return await permission
        .onGrantedCallback(() {
          if (kDebugMode) print('Permission granted: ${permission.toString()}');
        })
        .onLimitedCallback(() {
          if (kDebugMode) print('Permission limited: ${permission.toString()}');
        })
        .onDeniedCallback(() {
          if (kDebugMode) print('Permission denied: ${permission.toString()}');
        })
        .onPermanentlyDeniedCallback(() {
          if (kDebugMode) {
            print('Permission permanently denied: ${permission.toString()}');
          }
        })
        .onRestrictedCallback(() {
          if (kDebugMode) {
            print('Permission restricted: ${permission.toString()}');
          }
        })
        .request();
  }


}
